<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>执行环节-执行员环节</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/css/custom.form.css">
    <style type="text/css">
        .layui-disabled, .layui-disabled:hover {
            color: #000000 !important;
            cursor: not-allowed !important;
        }

        .layui-form-label {
            width: 100px;
        }

        .layui-input-block {
            margin-left: 130px;
        }

        .layui-input layui-unselect {
            cursor: pointer;
        }

        .layui-table {
            width: 96%;
        }
    </style>
</head>
<body>

<div class="layui-card-body">

    <div class="layui-tab table_div">
        <div class="layui-tab-content">
                <table class="layui-table" id="grdbShowTable" lay-filter="grdbShowTable"></table>
            </div>
        </div>
    </div>



</div>


<script type="text/html" id="grdbTool">

    {{#  if(d.stateCode == "2105"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="refuse">退回</a>
    {{#  }else if(d.stateCode == "21"){ }}
    <a class="layui-btn layui-btn-xs" lay-event="view1">接收</a>
    <a class="layui-btn layui-btn-xs" lay-event="refuse">拒绝</a>
    {{#  }else { }}
    <a class="layui-btn layui-btn-xs" lay-event="view">办理</a>
    {{#  } }}
</script>

<script src="/layui/layui.all.js"></script>
<script src="/layui-ext/selectM/selectM.js"></script>
<script src="/js/core.util.js"></script>
<script th:inline="none">
    // 获取token
    var token = CoreUtil.getData("access_token");
    // 地址栏转义token中的#号
    var tokenQuery = token.replace("#", "%23");

    var grdbTableIns;
    var grybTableIns;

    var table = layui.table;
    var form = layui.form;
    var layer = layui.layer;
    var $ = jQuery = layui.jquery;
    var laydate = layui.laydate;
    var upload = layui.upload;
    var element = layui.element;
    var maxlength = 500;
    var inspectionMan = "";
    var _inspectionMan = "";

    var meetMan = "";

    var selectM = layui.selectM;

    var syslog = {
        'operation': "hearPage21",
    };
    CoreUtil.sendPost("/sys/addLogs", syslog, function (res) {

    });
    layui.config({
        base: '/'
    }).extend({
        selectM: 'layui-ext/selectM/selectM',
    }).use(['table', 'layer', 'laydate', 'upload', 'element'], function () {
        // 个人待办
        grdbTableIns = table.render({
            elem: '#grdbShowTable',
            contentType: 'application/json',
            headers: {
                "authorization": token
            },
            url: '/workflow/hear/zxyzxhjgrdb',
            method: 'post',
            request: {
                limitName: 'rows', //每页数据量的参数名，默认：limit
                pageName: 'page',
            },
            where: {},
            cols: [[
                {
                    align: 'center',
                    width: 230,
                    field: 'jcajxxuuid',
                    title: '检查UUID',
                    sort: true,
                    hide: true
                }, {
                    align: 'center',
                    width: 180,
                    field: 'jcajbh',
                    title: '检查案件编号',
                    sort: true,
                },{
                    align: 'center',
                    width: 480,
                    field: 'ajmc',
                    title: '案件名称',
                    sort: true,
                },{
                    align: 'center',
                    width: 180,
                    field: 'ajztmc',
                    title: '案件状态',
                    sort: true,
                },{
                    align: 'center',
                    width: 380,
                    field: 'slry',
                    title: '审理人员',
                    sort: true,
                },{
                    align: 'center',
                    width: 190,
                    field: 'nsrsbh',
                    title: '纳税人识别号',
                    sort: true,
                }, {
                    align: 'center',
                    width: 240,
                    field: 'nsrmc',
                    title: '纳税人名称',
                    sort: true,
                },{
                    align: 'center',
                    width: 180,
                    field: 'qsje',
                    title: '欠税金额',
                    sort: true,
                },{
                    align: 'center',
                    width: 180,
                    field: 'zxdjrq',
                    title: '执行登记日期',
                    sort: true,
                    templet: function (d) {
                        if (!d.zxdjrq) {
                            return '';
                        }
                        return layui.util.toDateString(d.zxdjrq, 'yyyy-MM-dd');
                    }
                }
            ]],
            response: {
                statusName: 'result', //数据状态的字段名称，默认：code
                statusCode: 200, //成功的状态码，默认：0
                dataName: 'rows', //数据列表的字段名称，默认：data
                countName: 'total',//规定数据总数的字段名称，默认：count
            },
            page: true,
            parseData: function (res) {
                console.log(res);
                var dataList = res.data;
                var total = dataList.length; //请求的数据总数
                var list = []; //用来保存当前页显示的数据
                //前端模拟分页，获取当前页、分页显示数据量
                var page = $("#layui-table-page1").find(".layui-laypage-em").next().html();
                var limit = $("#layui-table-page1").find(".layui-laypage-limits select").val();
                console.log(page + ", " + limit);
                if (page == undefined || page == null || page == "") {
                    page = 1;
                }
                if (limit == undefined || limit == null || limit == "") {
                    limit = 10;
                }
                //数据从哪条数据开始
                var start = (page - 1) * limit;
                //数据从哪条数据结束
                var end = page * limit;
                if (end > total) {
                    end = total;
                }
                //取分页数据
                for (var i = start; i < end; i++) {
                    list.push(dataList[i]);
                }
                return {
                    "result": 200, //解析接口状态
                    "total": total, //解析数据长度
                    "rows": list //解析数据列表
                }
            },
            done: function (res) {
                setTimeout(function () {
                    // 安全获取数据，兼容res.data为null/undefined的情况
                    var data = res && res.rows ? res.rows : [];
                    console.log(data);

                    // 检查数据是否有效
                    if (!Array.isArray(data)) {
                        console.warn('Invalid data format:', data);
                        return;
                    }

                    // 颜色配置
                    var colors = {
                        1: '#98FB98',
                        2: '#FFA500',
                        3: '#f33636',
                        4: '#ADD8E6'
                    };

                    // 遍历数据
                    for (var i = 0; i < data.length; i++) {
                        try {
                            // 安全获取bh值并转换为数字
                            var bhValue = data[i] && data[i].bh;
                            var overdueDays = bhValue ? parseInt(bhValue, 10) : 0;

                            if (isNaN(overdueDays)) {
                                overdueDays = 0;
                            }

                            // 安全获取对应的行
                            var tr = $('div[lay-id="grdbShowTable"] .layui-table-main tbody tr').eq(i);

                            // 应用颜色样式
                            if (tr.length && colors[overdueDays]) {
                                tr.css('background-color', colors[overdueDays]);
                            }
                        } catch (e) {
                            console.error('Error processing row', i, ':', e);
                        }
                    }
                }, 100);
            }
        });

        // 个人待办表头工具
        table.on('grdbToolbar(grdbShowTable)', function (obj) {
            switch (obj.event) {
            }
        });


        // 列操作
        table.on('tool(grdbShowTable)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                case 'view':
                    view(data, "0");
                    break;
                case 'view1':
                    lock(data);
                    view(data, "0");
                    break;

                case 'refuse':
                    /* lock(data); */
                    $('#_jcajxxuuid').val(data.jcajxxuuid);
                    refuse();
                    break;
            }
        });

        // 返回
        $("#btn_cancel").click(function () {
            back();
            return false;
        });

        form.on('submit(demo)', function (data) {

            var formData = data.field;
            console.log('表单对象：', formData);
            var _meetManId = formData.meetManId;

            if (CoreUtil.isEmpty(_meetManId)) {
                layer.msg("会议审人员未选择！");
                return false;
            }

            var mapArr = {
                'jcajxxuuid': $('#_jcajxxuuid').val(),
                'meetMans': _meetManId,
            };

            CoreUtil.sendPost("/workflow/activity/meeting", mapArr,
                function (res) {
                    if (res.code === 0) {
                        layer.msg("成功 推送会议审！");
                        layer.closeAll();
                        back();
                        return false;
                    } else {
                        layer.msg(res.msg);
                        return false;
                    }
                });

        })

        $("#grdb").click(function () {
            grdbSearch();
        });

        $("#more").click(function () {
            $("#more").hide();
            $("#moreContent").show();
            $("#moreHide").show();
        });

        $("#moreHide").click(function () {
            $("#more").show();
            $("#moreContent").hide();
            $("#moreHide").hide();
        });

    });

    // 执行查询
    function gwdbSearch() {
        var gwdbInput = $("#gwdbInput").val();
        var _gwdbSelect = $("#gwdbSelect").val();

        grdbTableIns.reload({
            where: {
                sjbh: gwdbInput,
                yqzt: _gwdbSelect,
            },

            page: {
                curr: 1
            }
        });
    };

    function grdbSearch() {
        var grdbInput = $("#grdbInput").val();
        grdbTableIns.reload({
            where: {
                sjbh: grdbInput,
            },
            page: {
                curr: 1
            }
        });
    };


</script>

</body>
</html>